<template>
    <div class="shopcar-container">
        <div class="goods-list">
            <div class="mui-card">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<mt-switch></mt-switch>
                        <img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/
                        u=1951203608,1249893738&fm=26&gp=0.jpg">
                        <div class="info">
                            <h1>小米（Mi）小米note 16G双网通版</h1>
                            <p>
                                <span class="price">￥2199</span>
                                <numbox></numbox>
                                <a href="#" @click="remove">删除</a>
                            </p>
                        </div>
                        
					</div>
				</div>
			</div>
            
        </div>
<!-- 去结算 -->
<div class="mui-card">
				<div class="mui-card-content">
					<div class="mui-card-content-inner jiesuan">
						<div class="left">
                            <p>总计（不含运费）</p>
                            <p>已勾选商品<span class="red">0</span>件，总计<span class="red">￥2555</span></p>
                        </div>
                        <mt-button type="danger">去结算</mt-button>
					</div>
				</div>
			</div>


<!-- 样式 -->
<div class="goods-list">
            <div class="mui-card" v-for="(item,i) in goodslist" :key="item.id">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<mt-switch 
                        :v-model="$store.getters.getGoodsSelected[item.id]"
                        @change="selectedChange(item.id,$store.getters.getGoodsSelected[item.id])"></mt-switch>
                        <img :src="item.thumb_path">
                        <div class="info">
                            <h1>{{item.ttle}}</h1>
                            <p>
                                <span class="price">￥{{item.sell_price}}</span>
                                <numbox :initcount="$store.getters.getGoodsCount[item.id]" :goodsid="item.id"></numbox>
                                <a href="#" @click="remove(item.id,i)">删除</a>
                            </p>
                        </div>
                        
					</div>
				</div>
			</div>
           
        </div>


<!-- 去结算 -->
<!-- <div class="mui-card">
				<div class="mui-card-content">
					<div class="mui-card-content-inner jiesuan">
						<div class="left">
                            <p>总计（不含运费）</p>
                            <p>已勾选商品<span class="red">{{$store.getters.getGoodsAndCount.count}}</span>件，总计<span class="red">￥{{$store.getters.getGoodsAndCount.amount}}</span></p>
                        </div>
                        <mt-button type="danger">去结算</mt-button>
					</div>
				</div>
			</div> -->






    </div>
</template>

<script>
import numbox from '../subcomponents/shopcar_numbox.vue'

export default{
    data() {
        return {
            goodslist:[]
        }
    },
    created() {
        this.getGoodsList();
    },
    methods: {
        getGoodsList(){
            var idAll=[];
            this.$store.state.car.forEach(item => idAll.push(item.id));

            if(idAll.length<=0){
                return;
            }

            this.$http.get('api/goods/getshopcarlist/'+idAll.join(","))
            .then(result=>{
                if(result.body.status===0){
                    this.goodslist=result.body.message;
                }
            })
        },
        remove(id,index){
            this.goodslist.splice(index,1)
        },
        selectedChange(id,val){
                  // 每当点击开关，把最新的 快关状态，同步到 store 中
                  this.$store.commit("updateGoodsSelected",{id,selected:val})
        }
    },
    components:{
        numbox
    }
}


</script>

<style lang="scss" scoped>
.shopcar-container{
    background-color: #eee;
    overflow: hidden;
    .goods-list{
        .mui-card-content-inner{
            display: flex;
            align-content: center;
        }
        img{
            width: 60px;
            height: 60px;
        }
        h1{
            font-size: 13px;
        }
        .info{
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            .price{
                color:red;
                font-weight: bold;
            }
        }
    }
    .jiesuan{
        display: flex;
        justify-content: space-between;
        align-items: center;
        .red{
            color: red;
            font-size: 16px;
            font-weight: bold;
        }
    }
}
</style>